<?php
if (!defined("_ECRIRE_INC_VERSION")) return;
global $tables_principales;

function ecatalogue_declarer_tables_interfaces($interface){
    $interface['table_des_tables']['ecatalogue_products'] = 'ecatalogue_products';
    $interface['table_des_tables']['ecatalogue_options'] = 'ecatalogue_options';
    $interface['table_des_tables']['ecatalogue_articles_options'] = 'ecatalogue_articles_options';
    $interface['table_des_tables']['ecatalogue_groupes'] = 'ecatalogue_groupes';
    $interface['table_des_tables']['ecatalogue_currencies'] = 'ecatalogue_currencies';
    
    //Doesn't work    
    $interface['tables_jointures']['spip_ecatalogue_options']['id_article']= 'ecatalogue_articles_options';
    
	return $interface;
}

function ecatalogue_declarer_tables_principales($tables_principales){
    
    // spip_ecatalogue_products
    $ecatalogue_products = array(
		"id_article" 	=> "bigint(21) NOT NULL AUTO_INCREMENT",
		"price" 		=> "float NOT NULL",
        "priceold" 		=> "float NOT NULL",
		"sku" 	        => "varchar(50) NOT NULL",
		"quantity"      => "int(11) NOT NULL",
        "weight" 	    => "float NOT NULL",
        "width" 	    => "float NOT NULL",
        "height"    	=> "float NOT NULL",
        "length" 	    => "float NOT NULL",
        "extra1" 	    => "varchar(255) NOT NULL",
        "extra2" 	    => "varchar(255) NOT NULL",
        "extra3" 	    => "varchar(255) NOT NULL",
        "extra4"        => "varchar(255) NOT NULL",        
        "maj"           => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
		);
	$ecatalogue_products_key = array(
		"PRIMARY KEY"	=> "id_article"
		);
	$tables_principales['spip_ecatalogue_products'] =
		array('field' => &$ecatalogue_products, 'key' => &$ecatalogue_products_key);
        
    // spip_ecatalogue_options
    $ecatalogue_options = array(
		"id_option" 	   => "bigint(21) NOT NULL AUTO_INCREMENT",
		"titre" 		   => "varchar(255) NOT NULL",
        "id_groupe" => "bigint(21) NOT NULL",
        "maj"              => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
		);
	$ecatalogue_options_key = array(
		"PRIMARY KEY"	=> "id_option"
		);
	$tables_principales['spip_ecatalogue_options'] =
		array('field' => &$ecatalogue_options, 'key' => &$ecatalogue_options_key);
        
    // spip_ecatalogue_groupes
    $ecatalogue_groupes = array(
		"id_groupe" => "bigint(21) NOT NULL AUTO_INCREMENT",
		"titre"     => "varchar(255) NOT NULL",        
        "type"     => "enum('checkbox','select','radio') DEFAULT 'checkbox'",
        "maj"       => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
		);
	$ecatalogue_groupes_key = array(
		"PRIMARY KEY"	=> "id_groupe"
		);
	$tables_principales['spip_ecatalogue_groupes'] =
		array('field' => &$ecatalogue_groupes, 'key' => &$ecatalogue_groupes_key);    
        
    // spip_ecatalogue_currencies
    $ecatalogue_currencies = array(
		"id_currency" => "bigint(21) NOT NULL AUTO_INCREMENT",
		"titre"     => "varchar(255) NOT NULL",        
        "sign_pre"     => "varchar(50) NOT NULL",
        "sign_after"     => "varchar(50) NOT NULL",
        "code"     => "varchar(5) NOT NULL",
        "rate"     => "float NOT NULL",
        "maj"       => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
		);
	$ecatalogue_currencies_key = array(
		"PRIMARY KEY"	=> "id_currency",
        "INDEX" => "code"
		);
	$tables_principales['spip_ecatalogue_currencies'] =
		array('field' => &$ecatalogue_currencies, 'key' => &$ecatalogue_currencies_key);    
    
    return $tables_principales;
}

function ecatalogue_declarer_tables_auxiliaires($auxiliary_tables){        
    
    // spip_ecatalogue_articles_options
    $ecatalogue_articles_options = array(
		"id_article" 	   => "bigint(21) NOT NULL",
		"id_option" 	   => "bigint(21) NOT NULL",        
        "maj"              => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
		);
	$ecatalogue_articles_options_key = array(
		"PRIMARY KEY"	=> "id_article, id_option"
		);
	$auxiliary_tables['spip_ecatalogue_articles_options'] =
		array('field' => &$ecatalogue_articles_options, 'key' => &$ecatalogue_articles_options_key);
        
    // spip_ecatalogue_rubriques_currencies
    $ecatalogue_rubriques_currencies = array(
		"id_rubrique" 	   => "bigint(21) NOT NULL",
		"id_currency" 	   => "bigint(21) NOT NULL",        
        "maj"              => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
		);
	$ecatalogue_rubriques_currencies_key = array(
		"PRIMARY KEY"	=> "id_rubrique, id_currency"
		);
	$auxiliary_tables['spip_ecatalogue_rubriques_currencies'] =
		array('field' => &$ecatalogue_rubriques_currencies, 'key' => &$ecatalogue_rubriques_currencies_key);    
       
    return $auxiliary_tables;
}


?>